def MillimeterConvertPixel(Millimeter):#把毫米换算成像素
    return ((int)(Millimeter / 25.4 * 96) + 1)
import cv2
import numpy as np
import matplotlib.pylab as plt
fname = '/home/xys/CloundShiProjects/矫正/zheng.jpg'
# xfname = '/home/xys/CloundShiProjects/矫正/xuanzhuanxie.jpg'
xfname = '/home/xys/CloundShiProjects/矫正/test2.jpeg'

a = cv2.imread(xfname)
h = a.shape[0]
w = a.shape[1]
wh = max(w, h)

pts1 = np.float32([[50, 76], [28, 152], [1286, 53], [1306, 135]])  #获得目标图(歪斜)坐标（与原图坐标对应起来）
pts = np.float32([[17, 66], [17, 148], [1160, 58], [1160, 142]])  #获得原图坐标(正常)
# pts3 = np.float32([[152, 1060], [267, 1056], [129, 39], [200, 38]]) #旋转邪坐标
# pts3 = np.float32([[202, 948], [206, 1211], [3698, 316], [3795, 534]]) #旋转邪坐标
pts3 = np.float32([[232, 734], [289, 957], [3677, 256], [3694, 507]]) #旋转邪坐标


M = cv2.getPerspectiveTransform(pts3, pts)
dst1 = cv2.warpPerspective(a, M, (w+h, w))

plt.figure()
plt.subplot(221)
plt.imshow(a)
plt.subplot(222)
plt.axis('off')#去掉坐标轴
plt.imshow(dst1)
plt.show()